home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
cqa.zip
/
3PBGIAD.TC
next >
Wrap
Text File
|
1991-04-01
|
2KB
|
83 lines
QUESTION: How do I link a third party BGI driver into my program?
ANSWER: The following procedure and example should help you out.
(1) convert vga256.BGI to an object file with this command:
BGIOBJ vga256.BGI vga256.obj _vga256_driver
(2) Create a project file for the program that links in the driver.
The project should contain two items: 1) test.c 2) vga256.obj
(3) Here's what test.c would look like:
/*-------------------------- 3PBGIAD.C --------------------------*/
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
/* function prototypes */
int huge alwayszero(void);
void checkerrors(void);
void _Cdecl vga256_driver(void); /* DON'T FORGET THE PROTOTYPE! */
int main(void)
{
int gdriver, gmode;
/* install the user defined driver into the system */
gdriver = installuserdriver("vga256", alwayszero);
/* check for any installation errors */
checkerrors();
/* register the driver with the graphics system */
registerbgidriver(vga256_driver);
/* check for any installation errors */
checkerrors();
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* check for any initialization errors */
checkerrors();
/* draw a line */
setcolor(WHITE);
line(0, 0, getmaxx(), getmaxy());
/* clean up */
getch();
closegraph();
return 0;
} /* end of main() */
/*-------------------------------------------------------------------
alwayszero -
*/
int huge alwayszero(void)
{
return 0;
} /* end of alwayszero() */
/*-------------------------------------------------------------------
checkerrors - check for and report any graphics errors
*/
void checkerrors(void)
{
int errorcode;
/* read result of last graphics operation */
errorcode = graphresult();
if (errorcode != grOk) {
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
} /* end of checkerrors() */